import { request } from 'umi';
import { getBaseUrl } from '@/services/urlconst';
import { getTenant } from '@/utils';
import { departmentAPI } from '@/pages/SystemController/DepartmentController/type';

let baseUrl = getBaseUrl();

/**
 * 获取公司权限组织管理树
 *  /departmentController/getTreeByCompany
 */
export async function getTreeByCompanyData(
  params: departmentAPI.IDataRequestCompany,
) {
  let url = `${baseUrl}/departmentController/getTreeByCompany`;
  return request(url, {
    method: 'POST',
    toObj: false,
    headers: {
      tenantName: getTenant(),
    },
    data: {
      ...params,
    },
    requestType: 'json',
    charset: 'utf8',
    skipErrorHandler: true,
  });
}

/**
 * 获取部门权限组织管理树
 *  /departmentController/getTreeByDepart
 */
export async function getTreeByDepartData(
  params: departmentAPI.IDataRequestDepart,
) {
  let url = `${baseUrl}/departmentController/getTreeByDepart`;
  return request(url, {
    method: 'POST',
    toObj: false,
    headers: {
      tenantName: getTenant(),
    },
    data: {
      ...params,
    },
    requestType: 'json',
    charset: 'utf8',
    skipErrorHandler: true,
  });
}

// 添加组织机构  /departmentController/add
export async function addDepartment(params: any) {
  let url = `${baseUrl}/departmentController/add`;
  return request(url, {
    method: 'POST',
    toObj: false,
    headers: {
      tenantName: getTenant(),
    },
    data: {
      ...params,
    },
    requestType: 'json',
    charset: 'utf8',
    skipErrorHandler: true,
  });
}

// 编辑组织机构
export async function editDepartment(params: any) {
  let url = `${baseUrl}/departmentController/edit`;
  return request(url, {
    method: 'PUT',
    toObj: false,
    headers: {
      tenantName: getTenant(),
    },
    data: {
      ...params,
    },
    requestType: 'json',
    charset: 'utf8',
    skipErrorHandler: true,
  });
}

// 修改组织机构状态
export async function chanageModifyState(params: any) {
  let url = `${baseUrl}/departmentController/modifyState`;
  return request(url, {
    method: 'PUT',
    toObj: false,
    headers: {
      tenantName: getTenant(),
    },
    data: {
      ...params,
    },
    requestType: 'json',
    charset: 'utf8',
    skipErrorHandler: true,
  });
}

// 获取组织机构详情 /departmentController/getDepartmentByID
export async function getDeptDetail(
  params: departmentAPI.IDataRequestDeptDetail,
) {
  let url = `${baseUrl}/departmentController/getDepartmentByID/${params.deptID}`;
  return request(url, {
    method: 'GET',
    toObj: false,
    headers: {
      tenantName: getTenant(),
    },
    data: {
      ...params,
    },
    requestType: 'json',
    charset: 'utf8',
    skipErrorHandler: true,
  });
}
